time Event
Starts a timer for a specific event name to measure its duration.
When this method is called, the player records the current time as the start time for the given eventName. Later, when track or track is called for the same eventName, the elapsed time since this timeEvent call will be calculated. This duration, often referred to as "dwell time," is then automatically included as a property (e.g., "event_duration_ms") in the data sent with that track call.
Usage:
- Call
timeEvent("my_custom_event")to start the timer. - Perform actions related to "my_custom_event".
- Call
track("my_custom_event")ortrack("my_custom_event", properties)to stop the timer and send the event along with its calculated duration.
Behavior Notes:
- If
timeEventis called multiple times for the sameeventNamebefore a correspondingtrackcall, typically the last call totimeEventfor that eventName will be used as the start time. - You can time multiple distinct event names concurrently.
- If
track(eventName)is invoked for an event that was not previously started withtimeEvent(eventName), no duration property will be added. - Timed events are typically associated with the currently active event session (see newEventSession).
Parameters
event Name
The non-null name of the event to start timing. This name should match the eventName used in a subsequent track call to properly associate the duration.
See also
Throws
if eventName is null.
if eventName is empty.